<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:rich="http://richfaces.org/rich">
    <script type="text/javascript">
        function showContractList(contype) {
            if (contype == 0)
                window.open("./page/contract/pubinfo/conlist.jsf", "合同内容", "height=280,width=600,toolbar=no,menubar=no,scrollbars=no");
            else
                window.open("./page/contract/pubinfo/otherlist.jsf", "合同内容", "height=280,width=600,toolbar=no,menubar=no,scrollbars=no");
        }
        function showDetail(lineid) {
            currentLine = lineid;
            window.open("./page/contract/pubinfo/goodType.jsf", "合同内容", "height=280,width=600,toolbar=no,menubar=no,scrollbars=no");
        }
        function updateContent(code, name) {
            var form = document.forms['stock1'];
            form[[currentLine - 1] * 9 + 15].value = code;
            form[[currentLine - 1] * 9 + 16].value = name;
        }

        function setContract(code, name) {
            document.getElementById('stock1:number').value = code;
            document.getElementById('stock1:name').value = name;
        }
    </script>
    <style type="text/css">
        input[type='submit']{
            margin:3px 5px 3px 5px;
            padding:2px 5px 2px 5px;
        }
        .left{
            padding-right: 20px;
        }
        .right{
            vertical-align: top;
        }
    </style>
    <h:form id="stock1">
        <rich:panel header="合同执行单" id="editPanel" styleClass="content-hight">
            <rich:notifyMessage stayTime="3000"/> 

            <h:outputLabel value="选择合同：" />
            <h:inputText value="#{contractExecuteBean.mainInfo.number}" size="24"
                          disabled="#{contractExecuteBean.editStatus}"
                          onclick="#{rich:component('contractPanel')}.show();">
            </h:inputText>

            <a4j:commandButton value="确定" action="#{contractExecuteBean.contractQueryed}"
                               execute="@this" render="@form"
                               disabled="#{!contractExecuteBean.contractChanged
                                           or contractExecuteBean.editStatus}"/>

            <rich:toolbar  itemSeparator="grida" id="tolbar">
                <rich:toolbarGroup>
                    <a4j:commandButton value="新增" action="#{contractExecuteBean.add}" render="editPanel"
                                       disabled="#{contractExecuteBean.contractChanged}"/>
                    <a4j:commandButton value="修改" action="#{contractExecuteBean.update}" render="editPanel"
                                       disabled="#{contractExecuteBean.addOrUpdate or
                                                   empty contractExecuteBean.master.vounumber
                                                   or contractExecuteBean.contractChanged}"/>
                    <a4j:commandButton value="删除" action="#{contractExecuteBean.delete}" render="editPanel"
                                       disabled="#{contractExecuteBean.addOrUpdate or
                                                   empty contractExecuteBean.master.vounumber
                                                   or contractExecuteBean.contractChanged}"/>
                    <a4j:commandButton value="保存" action="#{contractExecuteBean.checkSave}" render="editPanel"
                                       disabled="#{not contractExecuteBean.editStatus
                                                   or contractExecuteBean.contractChanged}"
                                       onclick="this.disabled = 'true'"/>                    
                    <a4j:commandButton value="取消" action="#{contractExecuteBean.cancel}" render="editPanel"
                                       immediate="true"
                                       disabled="#{not contractExecuteBean.editStatus
                                                   or contractExecuteBean.contractChanged}"/>
                    <a4j:commandButton value="参照采购" onclick="#{rich:component('catePanel')}.show();"
                                       render="catePopuPanel"
                                       disabled="#{true or !contractExecuteBean.editStatus
                                                   or contractExecuteBean.contractChanged}"/>
                    <h:commandButton value="返回列表" action="#{contractExecuteBean.goback}"/>             
                    <a4j:commandButton value="已执行清单"
                                       onclick="#{rich:component('allExecPanel')}.show();"
                                       execute="@this" render="allExecGroup"
                                       disabled="#{contractExecuteBean.contractChanged}"/>
                </rich:toolbarGroup>
            </rich:toolbar>

            <h:panelGrid columns="4" width="80%" border="0" id="editGrid">

                <h:outputLabel value="合同代码:" />
                <a4j:commandLink execute="@this" render="contentGroup1"
                                 onclick="#{rich:component('contractPanel')}.show();">
                    <h:inputText  id="number1" value="#{contractExecuteBean.mainInfo.number}" size="24"
                                  disabled="#{not contractExecuteBean.editStatus}">
                        <a4j:ajax event="click" render="contractTable"/>
                    </h:inputText>
                </a4j:commandLink>

                <h:outputLabel value="合同名称:" />
                <h:inputText  id="name" value="#{contractExecuteBean.mainInfo.cname}" size="24"
                              disabled="#{not contractExecuteBean.editStatus}"/>

                <h:outputLabel value="合同类型:" />
                <h:inputText  id="contractTypeName" value="#{contractExecuteBean.mainInfo.contractTypeName}" size="24"
                              disabled="#{not contractExecuteBean.editStatus}"/>

                <h:outputLabel value="收付款类型:" />
                <h:inputText value="收款" rendered="#{contractExecuteBean.mainInfo.isPayCon eq 0}"
                             disabled="#{not contractExecuteBean.editStatus}"
                             readonly="true" size="24"/>  
                <h:inputText value="付款" rendered="#{contractExecuteBean.mainInfo.isPayCon eq 1}"
                             disabled="#{not contractExecuteBean.editStatus}"
                             readonly="true" size="24"/>  
                <h:inputText value="" rendered="#{not(contractExecuteBean.mainInfo.isPayCon eq 0 
                                                  or contractExecuteBean.mainInfo.isPayCon eq 1)}"
                             disabled="#{not contractExecuteBean.editStatus}"
                             readonly="true" size="24"/>

                <h:outputLabel value="对方单位" />
                <h:inputText  id="partnerName" value="#{contractExecuteBean.mainInfo.partner.name}" size="24"
                              disabled="#{not contractExecuteBean.editStatus}"/>

            </h:panelGrid>
            <hr/>
            <h:panelGrid columns="4" width="80%" border="0" id="editGrid1">
                <h:outputLabel value="执行单编号:" />
                <h:inputText value="#{contractExecuteBean.master.vounumber}" size="24"
                             readonly="true"
                             disabled="#{not contractExecuteBean.editStatus}"/>

                <h:outputLabel value="执行日期:" />
                <h:panelGroup>
                    <rich:calendar value="#{contractExecuteBean.master.voudate}"
                                   locale="Locale.CHINA"
                                   popup="true"
                                   datePattern="yyyy-MM-dd"
                                   showApplyButton="false"
                                   inputSize="24"
                                   style="width:200px"
                                   disabled="#{not contractExecuteBean.editStatus}"/>
                </h:panelGroup>
            </h:panelGrid>
            <hr/>

            <h:panelGroup id="editTable">
                <rich:dataScroller for="exeTable" execute="@this" render="editTable"/>
                <rich:dataTable  id="exeTable"
                                 value="#{contractExecuteBean.detailModel}"
                                 var="dl"
                                 rowKeyVar="index"
                                 rows="10"
                                 noDataLabel="无数据"
                                 style="width:100%;">
                    <rich:column style="text-align:center;">
                        <f:facet name="header">
                            <h:panelGroup style="white-space: nowrap;">
                                <a4j:commandLink value="点击增行" action="#{contractExecuteBean.addLine}"
                                                 render="@this,editTable"
                                                 onclick="this.disabled = 'true';"
                                                 style="text-decoration: none;"
                                                 rendered="false"
                                                 disabled="#{not contractExecuteBean.editStatus}">
                                </a4j:commandLink>
                                <a4j:commandLink execute="@this" render="contentGroup1"
                                                 onclick="#{rich:component('contentPanel')}.show();"
                                                 disabled="#{contractExecuteBean.contractChanged
                                                             or not contractExecuteBean.editStatus}">
                                    <h:outputText value="选择执行内容"/>
                                </a4j:commandLink>
                            </h:panelGroup>
                        </f:facet>
                        <h:outputText  value="#{index+1}"/>
                    </rich:column>
                    <h:column>
                        <f:facet name="header">执行内容</f:facet> 
                        <a4j:commandLink onclick="#{rich:component('contentPanel')}.show();"
                                         disabled="#{not contractExecuteBean.editStatus}"
                                         render="contentGroup">
                            <h:inputText id="contentName" size="15" value="#{dl.name}"
                                         disabled="#{not contractExecuteBean.editStatus}"/>
                            <a4j:param value="#{index}" assignTo="#{contractExecuteBean.contentRowIndex}"/>
                        </a4j:commandLink>
                    </h:column>
                    <h:column>
                        <f:facet name="header">技术要求</f:facet>
                        <h:inputText value="#{dl.technicrequirment}" size="15"
                                     disabled="#{not contractExecuteBean.editStatus}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">执行数量</f:facet>
                        <h:inputText value="#{dl.count}" size="10"
                                     disabled="#{not contractExecuteBean.editStatus}">
                            <a4j:ajax event="keyup" render="total"/>
                        </h:inputText>
                    </h:column>
                    <h:column>
                        <f:facet name="header">数量</f:facet>
                        <h:outputText value="#{dl.countInCon}"/>
                    </h:column>
                    <h:column >
                        <f:facet name="header">单价</f:facet>
                        <h:outputText value="#{dl.price}"/>
                    </h:column>
                    <rich:column style="width:60px">
                        <f:facet name="header">金额</f:facet>
                        <h:outputText id="total" value="#{dl.count * dl.price}"/>
                    </rich:column>
                    <h:column>
                        <f:facet name="header">备注</f:facet>
                        <h:inputText value="#{dl.memo}" size="15"
                                     disabled="#{not contractExecuteBean.editStatus}"/>
                    </h:column>
                    <h:column>
                        <a4j:commandLink value="删除" action="#{contractExecuteBean.delLine}" render="editTable"
                                         disabled="#{not contractExecuteBean.editStatus}"/>
                    </h:column>
                </rich:dataTable>
            </h:panelGroup>         
        </rich:panel>
    </h:form>

    <rich:popupPanel id="contractPanel" autosized="true">
        <f:facet name="header">合同列表</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('contractPanel')}.hide();">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <h:outputLabel  value="合同类型:"/>
            <h:selectOneMenu value="#{contractExecuteBean.contype}"
                             style="width:130px;">
                <f:selectItem itemValue="" itemLabel="--请选择--"/>
                <f:selectItem itemValue="0" itemLabel="主合同"/>
                <f:selectItem itemValue="1" itemLabel="补充合同"/>
                <a4j:ajax event="change" render="contractTable"/>
            </h:selectOneMenu>
            <hr/>
            <h:panelGroup id="contractTable">
                <rich:dataScroller for="tableEdit" execute="@this" render="contractTable"/>
                <div style="height: 300px;width:750px;overflow: auto;">
                    <rich:dataTable id="tableEdit"
                                    value="#{contractExecuteBean.mainInfoModel}" var="incontract"
                                    rowClasses="list-row-odd,list-row-even"
                                    headerClass="table-header"
                                    rows="6"
                                    style="width:1200px;margin-bottom:5px;"
                                    noDataLabel="无数据">
                        <rich:column sortBy="#{incontract.number}">
                            <f:facet name="header">编号</f:facet>
                            <a4j:commandLink value="#{incontract.number}"
                                             action="#{contractExecuteBean.changeContract}"
                                             onclick="#{rich:component('contractPanel')}.hide();"
                                             execute="@this" render="editPanel">
                            </a4j:commandLink>
                        </rich:column>
                        <rich:column sortBy="#{incontract.cname}">
                            <f:facet name="header">名称</f:facet>
                            <h:outputText value="#{incontract.cname}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.contractTypeName}">
                            <f:facet name="header">合同类别</f:facet>
                            <h:outputText value="#{incontract.contractTypeName}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.address}">
                            <f:facet name="header">地点</f:facet>
                            <h:outputText value="#{incontract.address}">
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.orderdate}">
                            <f:facet name="header">签订日期</f:facet>
                            <h:outputText value="#{incontract.orderdate}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.start}">
                            <f:facet name="header">开始日期</f:facet>
                            <h:outputText value="#{incontract.start}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.deadline}">
                            <f:facet name="header">截止日期</f:facet>
                            <h:outputText value="#{incontract.deadline}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.warranty}">
                            <f:facet name="header">质保日期</f:facet>
                            <h:outputText value="#{incontract.warranty}">
                                <f:convertDateTime dateStyle="medium"/>
                            </h:outputText>
                        </rich:column>
                        <rich:column sortBy="#{incontract.nameA}">
                            <f:facet name="header">甲方</f:facet>
                            <h:outputText value="#{incontract.nameA}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.nameAstand}">
                            <f:facet name="header">甲方法人</f:facet>
                            <h:outputText value="#{incontract.nameAstand}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.partner.name}">
                            <f:facet name="header">乙方</f:facet>
                            <h:outputText value="#{incontract.partner.name}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.partner.legalPerson}">
                            <f:facet name="header">乙方法人</f:facet>
                            <h:outputText value="#{incontract.partner.legalPerson}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.target}">
                            <f:facet name="header">标的</f:facet>
                            <h:outputText value="#{incontract.target}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.quality_margin}">
                            <f:facet name="header">质保金</f:facet>
                            <h:outputText value="#{incontract.quality_margin}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.penalty}">
                            <f:facet name="header">违约金</f:facet>
                            <h:outputText value="#{incontract.penalty}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.other}">
                            <f:facet name="header">其他</f:facet>
                            <h:outputText value="#{incontract.other}"/>
                        </rich:column>
                        <rich:column sortBy="#{incontract.pay}">
                            <f:facet name="header">付款条件</f:facet>
                            <h:outputText value="#{incontract.pay}"/>
                        </rich:column>
                        <f:facet name="footer"></f:facet>
                    </rich:dataTable>

                    <rich:jQuery selector="#tableEdit tr:odd" query="addClass('odd-row')" />
                    <rich:jQuery selector="#tableEdit tr:even" query="addClass('even-row')" />
                    <rich:jQuery selector="#tableEdit tr"
                                 query="mouseover(function(){jQuery(this).addClass('active-row')})"/>
                    <rich:jQuery selector="#tableEdit tr"
                                 query="mouseout(function(){jQuery(this).removeClass('active-row')})"/>
                </div>
            </h:panelGroup>

        </h:form>
    </rich:popupPanel>

    <rich:popupPanel id="contentPanel" autosized="true">
        <f:facet name="header">合同内容列表</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('contentPanel')}.hide();">关闭</h:outputLink>
        </f:facet>
        <h:form>
            
            <h:panelGroup id="contentGroup1" rendered="true"
                          layout="block" style="text-align: center;">
                <div style="height: 400px;overflow:auto;">
                    <rich:dataTable id="goodstype1"
                                    value="#{contractExecuteBean.contentModel}" var="gtmodel"
                                    rowKeyVar="index" rows="5"
                                    rowClasses="list-row-odd,list-row-even"
                                    headerClass="table-header"
                                    styleClass="formdata"
                                    style="width:600px;"
                                    noDataLabel="无数据">

                        <rich:column style="text-align:center;width:30px">
                            <h:selectBooleanCheckbox value="#{gtmodel.selected}"/>
                        </rich:column>

                        <rich:column id="contentNameRow1">
                            <f:facet name="header">合同内容</f:facet>
                            <h:outputText value="#{gtmodel.name}"/>
                        </rich:column>

                        <rich:column id="countCol">
                            <f:facet name="header">数量</f:facet>
                            <h:outputText value="#{gtmodel.count}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">单价</f:facet>
                            <h:outputText value="#{gtmodel.price}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">总价</f:facet>
                            <h:outputText id="total1" value="#{gtmodel.count * gtmodel.price}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">技术要求</f:facet>
                            <h:outputText value="#{gtmodel.tecrequire}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">备注</f:facet>
                            <h:outputText value="#{gtmodel.memo}"/>
                        </rich:column>
                        <f:facet name="footer">
                            <rich:dataScroller/>
                        </f:facet>
                    </rich:dataTable>
                </div>
                <a4j:commandButton value="确定" action="#{contractExecuteBean.contentSelected_rows}"
                                   onclick="#{rich:component('contentPanel')}.hide();"
                                   execute="goodstype1" render="editTable"/>
                <a4j:commandButton value="取消" onclick="#{rich:component('contentPanel')}.hide();"/>
            </h:panelGroup>
            <h:panelGroup id="contentGroup" rendered="false">
                <h:panelGrid width="100%" columns="1"  style="text-align:center;font-size:12pt;color:red">
                    <h:outputText value="合同【#{contractExecuteBean.master.number}】内容明细" />
                </h:panelGrid>
                <div style="height:300px;overflow:auto;">
                    <rich:dataTable id="goodstype"
                                    value="#{contractExecuteBean.contentModel}" var="gtmodel"
                                    rowKeyVar="index" rows="5"
                                    rowClasses="list-row-odd,list-row-even"
                                    headerClass="table-header"
                                    styleClass="formdata"
                                    style="width:600px;"
                                    noDataLabel="无数据">

                        <rich:column style="text-align:center;width:30px">
                            <a4j:commandLink value="选择" action="#{contractExecuteBean.contentSelected}"
                                             render="editTable"
                                             oncomplete="#{rich:component('contentPanel')}.hide();">
                            </a4j:commandLink>
                        </rich:column>

                        <rich:column id="contentNameRow">
                            <f:facet name="header">合同内容</f:facet>
                            <h:outputText value="#{gtmodel.name}"/>
                        </rich:column>

                        <rich:column>
                            <f:facet name="header">数量</f:facet>
                            <h:outputText value="#{gtmodel.count}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">单价</f:facet>
                            <h:outputText value="#{gtmodel.price}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">总价</f:facet>
                            <h:outputText id="total" value="#{gtmodel.count * gtmodel.price}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">技术要求</f:facet>
                            <h:outputText value="#{gtmodel.tecrequire}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">备注</f:facet>
                            <h:outputText value="#{gtmodel.memo}"/>
                        </rich:column>
                        <f:facet name="footer">
                            <rich:dataScroller/>
                        </f:facet>
                    </rich:dataTable>
                </div>
            </h:panelGroup>
        </h:form>
    </rich:popupPanel>


    <rich:popupPanel id="allExecPanel" autosized="true">
        <f:facet name="header">已执行清单</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('allExecPanel')}.hide();">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <h:panelGroup id="allExecGroup">
                <rich:dataScroller for="allExecTable" execute="@this" render="allExecGroup"/>
                <div style="height:300px;overflow:auto;">
                    <rich:dataTable  id="allExecTable"
                                     value="#{contractExecuteBean.allExecList}"
                                     var="dl"
                                     rowKeyVar="index"
                                     rows="10"
                                     noDataLabel="无数据"
                                     style="width:100%;">
                        <rich:column style="text-align:center;">
                            <f:facet name="header">
                                行号
                            </f:facet>
                            <h:outputText  value="#{index+1}"/>
                        </rich:column>
                        <h:column>
                            <f:facet name="header">单号</f:facet>                             
                            <h:outputText value="#{dl.vounumber}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">执行内容</f:facet>                             
                            <h:outputText value="#{dl.name}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">技术要求</f:facet>
                            <h:outputText value="#{dl.technicrequirment}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">执行数量</f:facet>
                            <h:outputText value="#{dl.count}"/>
                        </h:column>
                        <h:column>
                            <f:facet name="header">数量</f:facet>
                            <h:outputText value="#{dl.countInCon}"/>
                        </h:column>
                        <h:column >
                            <f:facet name="header">单价</f:facet>
                            <h:outputText value="#{dl.price}"/>
                        </h:column>
                        <rich:column style="width:60px">
                            <f:facet name="header">金额</f:facet>
                            <h:outputText value="#{dl.count * dl.price}"/>
                        </rich:column>
                        <h:column>
                            <f:facet name="header">备注</f:facet>
                            <h:outputText value="#{dl.memo}"/>
                        </h:column>
                    </rich:dataTable>
                </div>
            </h:panelGroup>
        </h:form>
    </rich:popupPanel>
</ui:composition>
